package com.kaoyaya.delivery.activity;

import android.content.Intent;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.googlecode.androidannotations.annotations.*;
import com.kaoyaya.util.StringUtil;

/**
 * 搜索
 * @author yubin
 * @date 2013-5-21
 */
@NoTitle
@EActivity(R.layout.activity_search)
public class SearchActivity extends BaseActivity {
	private String[] hotProductName = { "中文字", "aa", "aab", "be", "awg", "sefr", "wead", "aehr", "aewrh", "abgna" };
	private String[] hotProductCategory = { "a", "aa", "aab", "be", "awg", "sefr", "wead", "aehr", "aewrh", "abgna" };
	private String[] hotCourseTitle = { "a", "aa", "aab", "be", "awg", "sefr", "wead", "aehr", "aewrh", "abgna" };

	private ArrayAdapter<String> productNameAdapter;
	private ArrayAdapter<String> productCategoryAdapter;
	private ArrayAdapter<String> courseTitleAdapter;
	@ViewById TextView tvTitle;
	@ViewById AutoCompleteTextView actvName;// 产品名称
	@ViewById AutoCompleteTextView actvCategory;// 产品类别
	@ViewById AutoCompleteTextView actvSubject;// 科目
	@ViewById EditText etLowest;// 最低价
	@ViewById EditText etHighest;// 最高价
	@ViewById Button btnSearch;

	@AfterViews
	void calledAfterViewInjection() {
		tvTitle.setText("搜索");
		productNameAdapter = new ArrayAdapter<String>(context, R.layout.sherlock_spinner_dropdown_item, hotProductName);
		productCategoryAdapter = new ArrayAdapter<String>(context, R.layout.sherlock_spinner_dropdown_item, hotProductCategory);
		courseTitleAdapter = new ArrayAdapter<String>(context, R.layout.sherlock_spinner_dropdown_item, hotCourseTitle);
		actvName.setAdapter(productNameAdapter);
		actvCategory.setAdapter(productCategoryAdapter);
		actvSubject.setAdapter(courseTitleAdapter);
//		completionThreshold
	}
	
	@Click
	void btnSearch() {
		Intent data=new Intent();
		if (StringUtil.isNotTrimBlank(actvName.getText().toString())) {
			data.putExtra("name", actvName.getText().toString());
		}
		if (StringUtil.isNotTrimBlank(actvCategory.getText().toString())) {
			data.putExtra("category", actvCategory.getText().toString());
		}
		if (StringUtil.isNotTrimBlank(actvSubject.getText().toString())) {
			data.putExtra("subject", actvSubject.getText().toString());
		}
		if (StringUtil.isNotTrimBlank(etLowest.getText().toString())) {
			data.putExtra("lowest", etLowest.getText().toString());
		}
		if (StringUtil.isNotTrimBlank(etHighest.getText().toString())) {
			data.putExtra("highest", etHighest.getText().toString());
		}
		setResult(RESULT_OK, data);
		finish();
	}
}
